package com.petlab.forum;

import java.util.HashMap;

import org.springframework.stereotype.Component;

import com.petlab.common.GetCurrentTime;
import com.petlab.model.Article;
import com.petlab.service.impl.FilePath;

@Component("articleDispathcer")
public class ArticleDispatcherImpl implements ObjectSaveToXML {

	public void saveObjectToXMLFile(Object o) {

		String time = GetCurrentTime.getTime();
		Article article = (Article) o;

		HashMap<String, String> hashMap = new HashMap<String, String>();
		hashMap.put("articleId", String.valueOf(article.getArticleId()));
		hashMap.put("authorName", article.getAuthorName());
		hashMap.put("artilceTitle", article.getArticleTitle());
		hashMap.put("inTime", time);
		hashMap.put("commentNumbers", String.valueOf(0));

		String themeTitle = article.getThemeTitle();

		String filename = FilePath
				.getParentDirectory(FilePath.getParentDirectory(this.getClass()
						.getResource("/").getFile()))
				+ "forum/" + themeTitle + "/" + themeTitle + ".xml";

		AddDetailsToXMLFile.addAMessageToXMLFile(filename, hashMap);
	}
}
